﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Xml.Serialization;
namespace XYZshell.Game.CardGameEngine
{
	/// <summary>
	/// 卡片集合
	/// </summary>
	[Serializable]
	[XmlRoot("Cards")]
	public  class CardCollection:Collection<Card>
	{
		public CardCollection()
		{
		}
		public CardCollection( IList<Card> cards )
			: base( cards )
		{
		}
		/// <summary>
		/// 根据卡片名称从集合中找到指定卡片
		/// </summary>
		/// <param name="cardName">卡片名称</param>
		/// <returns>卡片</returns>
		public Card this[string cardName]
		{
	
			get
			{
				Card card =Items.First<Card>( ( c ) =>
				{
					return c.Name == cardName;
				} );
				return card;
			}
		}
		/// <summary>
		/// 把当前集合中卡片转移到目标集合
		/// </summary>
		/// <param name="target"></param>
		/// <param name="card"></param>
		public void Move( CardCollection target ,Card card)
		{

			Card it= Items.First<Card>( ( c ) =>
			{
				return  c == card;
			} );
			if (it != null)
			{
				target.Add( it );
				Items.Remove( it );
			}
		}
	}
}
